﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;

namespace SymWorld.Model
{
    public class WorldState
    {
        protected List<ParticleState> _particleStateList = new List<ParticleState>();
        private WorldState _prevWorldState;
        private double _delay;

        public ReadOnlyCollection<ParticleState> ParticleStateList
        {
            get { return _particleStateList.AsReadOnly(); }
        }
        public WorldState PrevWorldState
        {
            get { return _prevWorldState; }
            private set { _prevWorldState = value; }
        }
        public double Delay
        {
            get { return _delay; }
            private set { _delay = value; }
        }

        public WorldState CreateNextWorldState(double delay)
        {
            WorldState retNewWorldState = new WorldState();
            retNewWorldState.Delay = delay;
            retNewWorldState.PrevWorldState = this;
            foreach (ParticleState particleState in this.ParticleStateList)
                retNewWorldState._particleStateList.Add(particleState.CreateNextParticleState(retNewWorldState, delay));

            return retNewWorldState;
        }
        public double CalculateMinimalParticleDistance()
        {
            double minimalDistance = double.PositiveInfinity;
            foreach (ParticleState firstParticleState in _particleStateList)
                foreach (ParticleState secondParticleState in _particleStateList)
                    if (firstParticleState != secondParticleState)
                    {
                        double particleDistance = VectorExtension.Distance(firstParticleState.Position, secondParticleState.Position);
                        minimalDistance = Math.Min(minimalDistance, particleDistance);
                    }
            return minimalDistance;
        }
    }
}
